#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Solution
{
public:
    ListNode *getIntersectionNode(ListNode *dummyHeadLong, ListNode *dummyHeadShort, int d)
    {
        ListNode *l = dummyHeadLong->next, *s = dummyHeadShort->next;
        while (d-- > 0)
        {
            l = l->next;
        }
        while (l != s)
        {
            l = l->next;
            s = s->next;
        }
        return l;
    }

    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB)
    {
        ListNode *dummyHeadA = new ListNode(0, headA);
        ListNode *dummyHeadB = new ListNode(0, headB);
        ListNode *n = dummyHeadA;
        while (n->next != nullptr)
        {
            n = n->next;
            dummyHeadA->val++;
        }
        n = dummyHeadB;
        while (n->next != nullptr)
        {
            n = n->next;
            dummyHeadB->val++;
        }
        if (dummyHeadA->val <= dummyHeadB->val)
            return getIntersectionNode(dummyHeadB, dummyHeadA, dummyHeadB->val - dummyHeadA->val);
        else
            return getIntersectionNode(dummyHeadA, dummyHeadB, dummyHeadA->val - dummyHeadB->val);
    }

private:
    struct ListNode
    {
        int val;
        ListNode *next;
        ListNode() : val(0), next(nullptr) {}
        ListNode(int x) : val(x), next(nullptr) {}
        ListNode(int x, ListNode *next) : val(x), next(next) {}
    };
};

int main()
{
    // TODO
    return 0;
}
